import Mock from 'mockjs'

export default {
    // 获取用户登录及用户登录后左侧菜单栏的数据
    getMenu: config => {
        // 先判断(前端传入的数据)用户是否存在
        const { username, password } = JSON.parse(config.body);
        // 判断账号和密码是否对应
        if (username === 'root' && password === 'root') {
            return {
                code: 20000,
                data: {
                    menu: [
                        {
                            path: '/home',
                            name: 'home',
                            label: '首页',
                            icon: 's-home',
                            url: 'Home.vue'
                        },
                        {
                            path: '/mall',
                            name: 'mall',
                            label: '商品管理',
                            icon: 'video-play',
                            url: 'Mall.vue'
                        },
                        {
                            path: '/user',
                            name: 'user',
                            label: '用户管理',
                            icon: 'user',
                            url: 'User.vue'
                        },
                        {
                            label: '其他',
                            icon: 'location',
                            children: [
                                {
                                    path: '/page1',
                                    name: 'page1',
                                    label: '页面1',
                                    icon: 'setting',
                                    url: 'Page1.vue'
                                },
                                {
                                    path: '/page2',
                                    name: 'page2',
                                    label: '页面2',
                                    icon: 'setting',
                                    url: 'Page2.vue'
                                },
                            ]
                        },
                    ],
                    token: Mock.Random.guid(),
                    message: '获取成功'
                },
            }
        } else if (username === 'huangxiaonan' && password === '12345678') {
            return {
                code: 20000,
                data: {
                    menu: [
                        {
                            path: '/home',
                            name: 'home',
                            label: '首页',
                            icon: 's-home',
                            url: 'Home.vue'
                        },
                        {
                            path: '/mall',
                            name: 'mall',
                            label: '商品管理',
                            icon: 'video-play',
                            url: 'Mall.vue'
                        },
                    ],
                    token: Mock.Random.guid(),
                    message: '获取成功'
                },
            }
        } else {
            return {
                code: -999,
                data: {
                    message: '用户名或密码错误'
                },
            }
        }
    }
}